/**
 * Created by shanming on 2016/7/31.
 */
(function () {
    'use strict';
    app.controller('ModifyGoodsController', [
        '$scope', '$http','$modal', '$timeout','goodsClass', function ($scope, $http,$modal, $timeout,goodsClass) {

            goodsClass.getgoodMessage().then(function (data) {

            })
            $scope.GoodsCategory = {
                selected: [],
                items: null
            };
            $scope.GoodsLabels = {
                selected: [],
                items: null

            };
            //品牌
            $scope.GoodsBrands = {
                selected: [],
                items: null
            };
            //面料材质
            $scope.GoodsFmaterials = {
                selected: [],
                items:null
            };
            //里料材质
            $scope.GoodsImaterials = {
                selected: [],
                items: null
            };
            //面料品牌
            $scope.GoodsFbrands = {
                selected: [],
                items: null
            };
            //颜色
            $scope.GoodsColors = {
                selected: [],
                items:null
            };

            //保存新商品
            $scope.saveNewGood=function(){

                //标签
                var goods = $scope.goods;
                goods.goodsClassification = $scope.GoodsCategory.selected;
                goods.goodLabel = $scope.GoodsLabels.selected;
                goods.goodFabrics = $scope.GoodsFmaterials.selected;
                goods.goodLining = $scope.GoodsImaterials.selected;

                goodsClass.addnewGood($scope.goods);
            }
            /*//商品对象
            $scope.goods={
                name:'',//
                storagePrice:'',//
                goodsClassification:$scope.GoodsCategory.selected,
                tagPrice:'',
                goodLabel:$scope.GoodsLabels.selected,
                goodMessageFile:'',
                goodFabrics:$scope.GoodsFmaterials.selected,
                goodLining:$scope.GoodsImaterials.selected,
                goodPattern:'',//图案
                goodBrands:'',//
                goodElasticity:'',//弹性
                goodThickness:'',//厚度
                goodDescription:''//描述
                goodFBrands:''//面料品牌
            }*/

            var init = function () {
                //加载商品信息
                goodsClass.getGoodMessage(1).then(function(data){
                    var goodMessage=data;
                    $scope.goods = data;
                    $scope.GoodsCategory.selected = data.goodsClassification;
                    $scope.GoodsLabels.selected = data.goodLabel;
                    $scope.GoodsBrands.selected = data.goodBrands;
                    $scope.GoodsFmaterials.selected = data.goodFabrics;
                    $scope.GoodsImaterials.selected = data.goodLining;
                    $scope.GoodsFbrands.selected = data.goodFBrands;
                   // $scope.GoodsColors.selected = data.goodsColor;
                }).then(function(){
                    //初始化页面参数
                    goodsClass.getgoodMessage().then(function (data) {
                        console.log(data);
                        $scope.GoodsCategory.items = data.goodsCategery;
                        $scope.GoodsLabels.items = data.goodsLabel;
                        $scope.GoodsBrands.items = data.goodsBrand;
                        $scope.GoodsFmaterials.items = data.goodsFabric;
                        $scope.GoodsImaterials.items = data.goodsFabric;
                        $scope.GoodsFbrands.items = data.goodsFbrands;
                        $scope.GoodsColors.items = data.goodsColor;
                    })
                })

            }();

            //尺码
            $scope.sizeItems = {
                M:false,
                L:false,
                XL:false,
                XXL:false,
                LL:false,
                XSL:false,
                XS:false
            }
            

            $scope.addProps=function(item){
                TipService.setMessage('添加成功','success');
                console.log($scope.sizeItmes);
                var modalInstance = $modal.open({
                    templateUrl: 'tpl/goods/addProps.html',
                    controller: 'addPropsCtrl',
                    size: 'lg',
                    resolve:{
                        items: function () {
                            return item;
                        }
                    }
                });
            };


        }]);







})();